/**
 * Copyright (c) 2010 - 2012,  Inc. All rights reserved.
 * @fileoverview   添加用户
 * @author bowen liu | liubowen082@163.com
 * @version 1.1 | 2013-4-13
 * @example
 * {uploadBox // 容器名}
 */

$require('mod.cPrompt');
LJS.define('cpt.addUser',function(ljs){
	
	var addUser = {
		init:function(){
			var that = this;
			$('#addUser').on('click',function(){
							that.showAdd();  
											  })
			
			
			},
		showAdd:function(){
			var that = this;
			if(this.lay){
				this.lay.show();
				return
				}
			
			this.lay = new ljs.mod.cPrompt({
				tpl:'<div class="infor inforNew">\
					<div class="title"><span class="txt">信息提示</span><span class="btnExit"><a href="javascript:void(0)" event_type="close"></a></span></div>\
					<div class="fillList">\
						<ul>\
							<li class="fillTxt"><div class="tit">帐号：</div><div class="inputTxt"><input type="text" node_type="userZH"></div></li>\
							<li class="fillFg"></li>\
							<li class="fillTxt"><div class="tit">姓名：</div><div class="inputTxt"><input type="text" node_type="userName""></div></li>\
							<li class="fillFg"></li>\
							<li class="fillFg"></li>\
							<li class="fillTxt"><div class="tit">手机：</div><div class="inputTxt"><input type="text" node_type="phonoNum"></div></li>\
							<li style="height:25px;" class="doomTxt" ><div class="tit">&nbsp;</div><div class="pro02" style="display:none" node_type="error"><span class="colorRem" ></span></div></li>\
						</ul>\
					</div>\
					<div class="btnEn"><a class="btn-et" event_type="ok" href="javascript:void(0)"><span>确定</span></a><a class="btn-ex" href="javascript:void(0)" event_type="close"><span>取消</span></a></div>\
				</div>'
			});
			this.lay.show();
			$('[event_type="ok"]',this.lay.win).on('click',function(e){
				that.post();
				return false;
			})
			},
		post:function(){
			$('[node_type="error"]',$(this.lay.win)).hide()
			var data = this.check(),that = this;
			
			if(!data){
				$('[node_type="error"]',$(that.lay.win)).show().find('.colorRem').html('请完整填写用户信息')
				return 
				}
			$.ajax({
			  type: "post",
			  url: "admin_add",
			  dataType: "json",
			  data:data,
			  cache:false,
			  success:function(json){
				  if(json.status=='100000'){
					  window.location.reload();
				  }else if(json.status=='100003'){
                	window.location.href = json.content.url;
                }else{
					  $('[node_type="error"]',$(that.lay.win)).show().find('.colorRem').html('用户已经存在')
					  }
			  }
			});
			},
		check:function(){
			if(!this.lay){
				return
				}
			var userZH = $.trim($('[node_type="userZH"]',$(this.lay.win)).val());
		    //var email = $.trim($('[node_type="email"]',$(this.lay.win)).val());
		    var userName = $.trim($('[node_type="userName"]',$(this.lay.win)).val());
		    var phonoNum = $.trim($('[node_type="phonoNum"]',$(this.lay.win)).val());
			
			if(userZH==''||userName==''||phonoNum==""){
				
				return false
				}
			return {
				action:'add',
				user:userZH,
				//email:email,
				userName : userName,
				phonoNum : phonoNum
				}
			}
		}

    return addUser;
    
});
